<template>
  <div>
    <!-- ElementUI:布局容器 -->
    <el-container>
      <el-aside width="200px">
        <!-- ElementUI:导航菜单 
             unique-opened:是否只保持一个子菜单的展开
             router:是否使用 vue-router 的模式，启用该模式会在激活导航时以 index 作为 path 进行路由跳转
        -->
        <el-row class="tac">
          <el-col :span="12">
            <el-menu
              :router="true"
              :unique-opened="true"
              default-active="2"
              class="el-menu-vertical-demo"
              background-color="#20222A"
              text-color="#fff"
              active-text-color="#ffd04b"
            >
              <el-menu-item index="2">
                <i class="el-icon-menu"></i>
                <span slot="title">首页</span>
              </el-menu-item>
              <!-- 根据已登录的帐号所分配的菜单来动态展示菜单内容： -->
              <el-submenu :index="items.id+''" v-for="items in menuArr" :key="items.id">
                <!-- 一级菜单项 -->
                <template slot="title">
                  <i :class="items.icon"></i>
                  <span>{{items.title}}</span>
                </template>
                <!-- 二级菜单项 -->
                <el-menu-item v-for="obj in items.children?items.children:[]" :key="obj.id" :index="obj.url">{{obj.title}}</el-menu-item>
              </el-submenu>      
                   
              <!--
              <el-submenu index="1">
                <template slot="title">
                  <i class="el-icon-document"></i>
                  <span>系统设置</span>
                </template>
                <el-menu-item index="/menus">菜单管理</el-menu-item>
                <el-menu-item index="/roles">角色管理</el-menu-item>
                <el-menu-item index="/manage">管理员管理</el-menu-item>
              </el-submenu>
              <el-submenu index="3">
                <template slot="title">
                  <i class="el-icon-setting"></i>
                  <span>商城管理</span>
                </template>
                <el-menu-item index="/category">商品分类</el-menu-item>
                <el-menu-item index="/specs">商品规格</el-menu-item>
                <el-menu-item index="/goods">商品管理</el-menu-item>
                <el-menu-item index="3-4">会员管理</el-menu-item>
                <el-menu-item index="3-5">轮播图管理</el-menu-item>
                <el-menu-item index="3-6">秒杀活动</el-menu-item>
              </el-submenu>
              -->
            </el-menu>
          </el-col>
        </el-row>
      </el-aside>
      <el-container>
        <el-header>
          <div>
            欢迎您{{userName}}回来&nbsp;&nbsp;
            单击这里<a href="#" @click="logout">退出系统</a>
          </div>
        </el-header>
        <el-main>
          <!-- Element UI:面包屑 -->
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{$route.meta.title}}</el-breadcrumb-item>
          </el-breadcrumb>
          <!-- 设置二级路由出口 -->
          <router-view></router-view>          
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data(){
    return{
      userName:'',//已登录的帐号
      menuArr:[],//已登录的帐号所分配的菜单
    }
  },
  methods:{
    //退出系统
    logout(){
        //清除本地sessionStorage中存储的登录帐号信息：
      //  sessionStorage['manaInfos'] = '';
      delete sessionStorage.manaInfos;
      this.$router.push('/denglu');
    }
  },
  mounted(){
    //获取已登录的帐号：
    this.userName =  sessionStorage['manaInfos']?JSON.parse(sessionStorage['manaInfos']).username:'';
    //已登录的帐号所分配的菜单
    this.menuArr = sessionStorage['manaInfos']?JSON.parse(sessionStorage['manaInfos']).menus:[];
  }
};
</script>

<style scoped>
.el-aside {
  width: 80px;
  height: 100vh;
  background-color: #20222a;
}

.el-header {
  height: 70px;
  width: 100vw;
  background-color: #b3c0d1;
}

.el-col {
  width: 100vw;
}

.el-breadcrumb{
  margin-bottom: 10px;
}
</style>